﻿using System;
using System.Net.Mail;
using Common;

namespace CSC440TeamOne.CSC440BusinessService.Services
{
    class ClientSideSendEmails
    {
        public void SendEmail(User user, Message message)
        {
            MailAddress Sender = new System.Net.Mail.MailAddress(message.Sender.EmailAddress);
            String sreciver = message.Reciver.ToString();
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = Sender;
            mail.To.Add(sreciver);
            mail.Subject = message.Subject;
            mail.Body = message.Body;
            try
            {
                if (mail.To.Count > 0 &&mail.Subject.Length>0 &&mail.Body.Length>0)
                {
                    SmtpServer.Port = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("csc440teamone", "dyatzeck");
                    SmtpServer.EnableSsl = true;
                    SmtpServer.Send(mail);
                }
                else
                {}
            }
            catch
            {

            }
        }
    }
}
